package com.promise.jokerdream.ui.settings

import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.promise.jokerdream.database.entity.MistyGameConfigEntity
import com.promise.jokerdream.ui.components.SettingCard
import com.promise.jokerdream.ui.components.SingleSelectHashtagBottomSheet
import com.promise.jokerdream.ui.components.SelectionRow
import com.promise.jokerdream.ui.theme.AppSpacing
import com.promise.jokerdream.ui.theme.AppFontSizes
import com.promise.jokerdream.model.misty.MistyMapping
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue

/**
 * 幻境设置卡片
 */
@Composable
fun MistySettingCard(
    config: MistyGameConfigEntity,
    onMistyChange: (Boolean) -> Unit,
    onMistyTextChange: (String) -> Unit,
    modifier: Modifier = Modifier,
    onExecuteClick: (() -> Unit)? = null
) {
    var showBottomSheet by remember { mutableStateOf(false) }
    SettingCard(
        title = "幻境",
        description = "",
        checked = config.enabledSetting,
        onCheckedChange = onMistyChange,
        modifier = modifier,
        onExecuteClick = onExecuteClick,
        content = {
            if (config.enabledSetting) {
                Column(
                    modifier = Modifier.fillMaxWidth()
                ) {
                    // 副本选择区域
                    SelectionRow(
                        label = "当前副本：",
                        selectedText = config.selectedMistyText.ifEmpty { "未选择" },
                        onClick = { showBottomSheet = true }
                    )
                }
            }
        }
    )
    
    // 副本选择底部弹窗
    if (showBottomSheet) {
        SingleSelectHashtagBottomSheet(
            title = "选择副本",
            initialText = config.selectedMistyText,
            placeholder = "支持输入1或1-乐斗村",
            recommendedTags = MistyMapping.getAllIdNameFormats(),
            onCancel = { showBottomSheet = false },
            onComplete = { selectedFormat ->
                onMistyTextChange(selectedFormat)
                showBottomSheet = false
            },
            onDismiss = { showBottomSheet = false }
        )
    }
}
